package com.gitee.fantaros.web.fan.netcut.threading;

import jakarta.validation.constraints.NotNull;

import java.util.concurrent.*;

public class ThreadPoolUtil {
    private static final ThreadFactory THREAD_FACTORY = new NamebleThreadFactory("ollama-req-");
    private static final ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(8, 8,
            5L, TimeUnit.MINUTES, new LinkedBlockingQueue<>(), THREAD_FACTORY);

    public static <T> T submitToThreadPool(Callable<T> callable) throws ExecutionException, InterruptedException {
        Future<T> future = THREAD_POOL_EXECUTOR.submit(callable);
        return future.get();
    }

    public static void executeOnThreadPool(@NotNull Runnable runnable) {
        THREAD_POOL_EXECUTOR.execute(runnable);
    }
}
